package com.jiuyun.servlet;

import com.google.gson.Gson;
import com.jiuyun.dao.WorkDao;
import com.jiuyun.dao.impi.WorkDaoImpl;
import com.jiuyun.entity.Kqcx;
import com.jiuyun.entity.Work;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;


@WebServlet("/work/*")
public class WorkServlet extends BaseServlet {
    Gson gson=new Gson();
    WorkDao dao=new WorkDaoImpl();

    //查找班级
    protected void find(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("111");
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json");
        String name1=request.getParameter("name");
        PrintWriter out=response.getWriter();
        List list=null;
        try {
            list=dao.findcs();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        String t=gson.toJson(list);
        System.out.println(t);
        out.println(t);
        out.flush();
        out.close();
    }
    //查找作业情况
    protected void findwork(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("1111");
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json");
        String kname=request.getParameter("bname");
        String yue=request.getParameter("kda");
        PrintWriter out=response.getWriter();
        List<Kqcx> list=null;
        String moth=yue.substring(5, 7);
       System.out.println(kname+"----1"+moth);

        try {
            list=dao.finwo(kname,moth);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        String t=gson.toJson(list);
        System.out.println(t);
        out.print(t);
        out.flush();
        out.close();
    }
    //添加作业情况
    protected void addwork(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("UTF-8");
        HttpSession session=request.getSession();
        int id=Integer.parseInt(request.getParameter("stuid"));
        System.out.println("77");
        String  ase=request.getParameter("case");
        String ctime=request.getParameter("time");
        String remak=request.getParameter("remak");
        String stuid2=request.getParameter("stuid");
        int num=0;
        try {
          num= dao.addrecord(id,ase,ctime,remak);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        if(num>0){
            request.getRequestDispatcher("/work.jsp").forward(request,response);
        }
    }
    //搜索试卷
    protected void seek(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        System.out.println("111");
        request.setCharacterEncoding("UTF-8");
       String eid=request.getParameter("search");
        List<Work> list=dao.findseex(eid);
        System.out.println("777");
        request.setAttribute("list",list);
        request.getRequestDispatcher("/seek.jsp").forward(request,response);
        System.out.println("778");
    }
    //详细查看考试内容
    protected void seexexam(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        System.out.println("1001");
        request.setCharacterEncoding("UTF-8");
        String tz=request.getParameter("tz");
        List<Work> list=dao.findseex(tz);
        request.getRequestDispatcher("/Eventstar/exam.jsp").forward(request,response);

    }
}
